<?php
namespace app\common\model\tyyh;

class UserWallet extends CUBase {
	protected $privacyFields   = ['createtime', 'updatetime'];

	//创建钱包
	public function createWallet($uid) {
		static::save([
			'uid'     => $uid,
			'balance' => 0,
			'cash'    => 0
		]);
	}

	//获取用户的钱包数据
	public function getWallet($uid) {
		$row = $this->where('uid', $uid)->field('uid,balance,cash')->find();
		if(empty($row)) {
			static::createWallet($uid);
			$row = $this->where('uid', $uid)->field('uid,balance,cash')->find();
		}
		return $row;
	}
}
